package com.library.control.login;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractFormController;

import com.library.model.dto.login.LoginDTO;
import com.library.model.service.LoginService;

public class LoginController extends AbstractFormController {

	private LoginService loginservice;
	
	
	
	public void setLoginservice(LoginService loginservice) {
		this.loginservice = loginservice;
	}

	@Override
	protected ModelAndView processFormSubmission(HttpServletRequest request,
			HttpServletResponse response, Object obj, BindException arg3)
			throws Exception {
		ModelAndView mav=new ModelAndView();
		LoginDTO dto=loginservice.getLogin((LoginDTO)obj);
		request.getSession().setAttribute("login", dto);
		mav.setViewName("mainlogin");
		return mav;
	}

	@Override
	protected ModelAndView showForm(HttpServletRequest arg0,
			HttpServletResponse arg1, BindException arg2) throws Exception {
		return new ModelAndView("mainlogin");
	}

}
